import com.sun.deploy.util.ArrayUtil;
import com.sun.deploy.util.StringUtils;

import java.util.*;

class Card{
    private  String col;
    private  int num;

    public Card(String col, int num) {
        this.col = col;
        this.num = num;
    }

    @Override
    public String toString() {
        return "[*" +col+num+"*]";
    }
}
public class MyArrayLiat {
    public static final String[] four = {"♥","♠","♣","♦"};
    //买牌
    public static ArrayList<Card> buyCard(){
        ArrayList<Card> fu = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            for (int j = 1; j < 14; j++) {
                String col = four[i];
                Card card = new Card(col,j);
                fu.add(card);
            }
        }
        return fu;
    }
    //洗牌
    public static ArrayList<Card> xiCard(ArrayList<Card> fu){
        for (int i = 0; i < fu.size(); i++) {
            Random random = new Random();
            int index = random.nextInt(fu.size()-1);
            Card tmp = fu.get(i);
            fu.set(i,fu.get(index));
            fu.set(index,tmp);
        }
        return fu;
    }
    //发牌
    public static ArrayList<ArrayList<Card>> faPai(ArrayList<Card> fa){
        ArrayList<ArrayList<Card>> test = new ArrayList<>();
        ArrayList<Card> hand1 = new ArrayList<>();
        ArrayList<Card> hand2 = new ArrayList<>();
        ArrayList<Card> hand3 = new ArrayList<>();
        test.add(hand1);
        test.add(hand2);
        test.add(hand3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card index = fa.remove(0);
                test.get(j).add(index);
            }
        }
        return test;
    }
    public static void main(String[] args) {
        ArrayList<Card> fu = buyCard();
        System.out.println("买牌"+fu);
        ArrayList<Card> xi = xiCard(fu);
        System.out.println("洗牌"+xi);
        ArrayList<ArrayList<Card>> fa = faPai(xi);
        System.out.println("总发牌"+fa);
        System.out.println("发牌1"+fa.get(0));
        System.out.println("发牌2"+fa.get(1));
        System.out.println("发牌3"+fa.get(2));
        System.out.println("剩余的牌"+xi);
    }
    public static ArrayList<Character> cut(String str1,String str2){
       ArrayList<Character> arr = new ArrayList<>();
        for (int i = 0; i < str1.length(); i++) {
            for (int j = 0; j < str2.length(); j++) {
                char x = str1.charAt(i);
                char y = str2.charAt(j);
                if(x == y){
                    break;
                }
                if(j == str2.length()-1){
                    arr.add(str1.charAt(i));
                }
            }
        }
        return arr;
    }
    public static void main5(String[] args) {
        String str1 = "welcome to bit";
        String str2 = "come";
        ArrayList<Character> arr = cut(str1,str2);
        System.out.println(arr);
    }

    //杨辉三角
    public static void main4(String[] args) {
        ArrayList<ArrayList<Integer>> yang = new ArrayList<>();
        int x = 8;
        ArrayList<Integer> one = new ArrayList<>();
        one.add(1);
        yang.add(one);
        for (int i = 1; i < x; i++) {
            ArrayList<Integer> cur = new ArrayList<>();
            cur.add(1);
            ArrayList<Integer> qian = yang.get(i-1);
            for (int j = 1; j < i; j++) {
                Integer cum = qian.get(j)+qian.get(j-1);
                cur.add(cum);
            }
            cur.add(1);
            yang.add(cur);
        }
        for (ArrayList<Integer> arr:yang) {
            System.out.println(arr);
        }
    }

    public static void main3(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(0,0);
        arrayList.add(1,99);
        // arrayList.add(3,1); 插入数据必须连续
        System.out.println(arrayList);
        System.out.println("==============");
        //使用其他的集合，来构造当前的list
        ArrayList<Integer> arrayList2 = new ArrayList<>(arrayList);
        //指定数组初始容量 15
        // ArrayList<Integer> arrayList3 = new ArrayList<>(15);
        arrayList2.add(2,2);
        arrayList2.add(3,3);
        System.out.println(arrayList2);
        //数组截取 截取函数是在数组本身上截取的
        List<Integer> list = arrayList2.subList(1,3);
        System.out.println(list);
        arrayList2.remove(0);
        System.out.println(arrayList2);
        arrayList2.remove(new Integer(99));
        System.out.println(arrayList2);
        System.out.println("==========");
        //获取一个迭代器
        Iterator<Integer> it = arrayList2.iterator();
        while (it.hasNext()){
            System.out.print(it.next() + " ");
        }
    }

    public static void main2(String[] args) {
        String[] arr = {"1","2","3"};
        int[] arr1 = new int[3];
        arr1[0] = 0;
        arr1[1] = 1;
        arr1[2] = 2;
        String str2 = ArrayUtil.arrayToString(arr);//整形数组不能使用
        System.out.println(str2);
        System.out.println(arr1);
        System.out.println("==========");
        ArrayList<String> arr2 = new ArrayList<>();
        arr2.add("1");
        arr2.add("2");
        arr2.add("3");
        System.out.println(arr2);
        String str3 = StringUtils.join(arr2,",");//ArrayList独有的方法
        System.out.println(str3);
    }

    public static void main1(String[] args) {
        int[] arr = new int[5];
        arr[2] = 2;
        arr = Arrays.copyOf(arr,2*arr.length);
        for (int i:arr) {
            System.out.println(i);
        }
    }
}
